using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace SecondLevelCaching.Data.Models.Mapping
  {
      public class OrderDetailMap : EntityTypeConfiguration<OrderDetail>
      {
          public OrderDetailMap()
          {
              // Primary Key
              this.HasKey(t => new { t.OrderID, t.ProductID });
  
              // Properties
              this.Property(t => t.OrderID)
                  .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
  
              this.Property(t => t.ProductID)
                  .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
  
              // Table & Column Mappings
              this.ToTable("Order Details");
              this.Property(t => t.OrderID).HasColumnName("OrderID");
              this.Property(t => t.ProductID).HasColumnName("ProductID");
              this.Property(t => t.UnitPrice).HasColumnName("UnitPrice");
              this.Property(t => t.Quantity).HasColumnName("Quantity");
              this.Property(t => t.Discount).HasColumnName("Discount");
  
              // Relationships
              this.HasRequired(t => t.Order)
                  .WithMany(t => t.Order_Details)
                  .HasForeignKey(d => d.OrderID);
              this.HasRequired(t => t.Product)
                  .WithMany(t => t.Order_Details)
                  .HasForeignKey(d => d.ProductID);
  
          }
      }
  }